﻿<?php



  $id = empty($_GET['id'])?'':$_GET['id'];//获取地址栏中的参数名是Id的值

 //双击编辑修改功能
 //判断是否是AJAX请求
  if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])&&$_POST['achieve']<0) {
       $val= $_POST['val'];
       $title= $_POST['title'];
       $sql= "update `news`  set $title='$val' where id=$id ";
       mysqli_query($link,$sql);
       echo mysqli_affected_rows($link);
       die;
  }


   //审核状态修改
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
     $id= $_POST['id'];
     $achieve= $_POST['achieve'];
      // $update[]= {$id, $achieve};
    // echo db_update('news',($id, $update));die;
     $sql= "update `news`  set `achieve`='$achieve' where id=$id ";
     mysqli_query($link,$sql);
     echo mysqli_affected_rows($link);
     die;
   }




//删除列表数据
if(!empty($_POST)){
       //获取$_POST数据
       $title=$_POST['title'];
       $type =$_POST['type'];
       $url = $_POST['url'];
       $content = $_POST['content'];


    $where['title']=$title;
    $where['type']=$type;
    $where['url']=$url;
    $where['content']=$content;
    $rows=db_update('news',$where);
    // print_r($where);die;
    // $sql = "update `news`  set `title`='$title',`type`='$type',`content`='$content'  where `id`='$id' ";
    // mysqli_query($link,$sql);
    // $rows = mysqli_affected_rows($link); //获取刚刚执行添加语句受影响的行数
    if ($rows>0) {
    echo '<script>alert("添加成功");location.href="index.php?c=news&a=list&admin=1"</script>';die;
    }else{
    echo '<script>alert("添加失败");history.go(-1);</script>';die;
     }
}

$sql = "SELECT * FROM  `news` where `id`= $id";//编写查询语句
        $result = mysqli_query($link,$sql);//执行语句
        $data = mysqli_fetch_assoc($result);


   include (VIEW_LAYER.'/admin/layout.html'); //视图加载页面


?>


